﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="BookDetails.aspx.vb" Inherits="BooksReviewApp.BookDetails" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
   

    <div class="Picture">
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <h2>
                    <%# Eval("BookName") %></h2>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <asp:HyperLink ID="Hl_Category" runat="server" Text='<%# Eval("Category")%>' NavigateUrl='<%# Eval("Category", "BooksByCategory.aspx?Category={0}")%>'
                    ForeColor="#009999" Font-Bold="False" Font-Size="Small">
                </asp:HyperLink>
                •
                <asp:HyperLink ID="Hl_SubCategory" runat="server" Text='<%# Eval("SubCategory")%>' NavigateUrl='<%# Eval("SubCategory", "BooksBySubCategory.aspx?SubCategory={0}")%>'
                    ForeColor="Orange" Font-Bold="False" Font-Size="Small">
                </asp:HyperLink>
                <br />
                &nbsp;By •
                <asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("Bibliophile")%>' NavigateUrl='<%# Eval("Bibliophile", "Profile.aspx?Bibliophile={0}")%>'
                    ForeColor="Red" Font-Bold="True" CssClass="red" Font-Size="Smaller">
                </asp:HyperLink>
                <br />
            </ItemTemplate>
        </asp:Repeater>
        <asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl='<%# String.Format("https://www.bookdepository.com/search?searchTerm={0}", Eval("BookName"))%>'>
                <img src="../../<%# (Eval("Picture")) %>" alt="No Picture" width="210" height="280" />
                </asp:HyperLink>
            </ItemTemplate>
        </asp:Repeater>
        <br />
        <asp:Repeater ID="Repeater4" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
            Posted • 
                <asp:Label ID="lbl_Time" runat="server" Text='<%# CalculateTime.calculateTime(Eval("DateAdded")) %>'
                    ForeColor="#009999" />
                • Total Views
                <asp:Label ID="lbl_Views" runat="server" Text='<%# getViews(Eval("ID")) %>' CssClass="myButton" />
            </ItemTemplate>
        </asp:Repeater>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                
                <span class="FavoriteButton">
                    <asp:Button ID="btn_AddGuide" runat="server" Text="Add To Guide" CssClass="m-btn blue" /><br />
                    <asp:Button ID="btn_Favorites" runat="server" Text="Add As Favorite" CssClass="m-btn blue" /></span>
                <span class="LikeButton">
                    <br />
                    <br />
                    <asp:Button ID="btn_Likes" runat="server" Text="Like it!" CssClass="m-btn purple" />
                    <asp:Repeater ID="rpt_Likes" runat="server" DataSourceID="SqlDataSource2">
                        <ItemTemplate>
                        • <span id="Span1" runat="server" title='<%# Eval("TotalLikes") & "Likes" %>'>
                        <asp:Label ID="lbl_Views" runat="server" Text='<%# Eval("TotalLikes") %>' CssClass="myButton" /></span>
                        </ItemTemplate>
                    </asp:Repeater>
                </span>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
     <div class="BasicInformation">
        <br />
        <br />
        <h3>
            Description</h3>
        <br />
        <br />
        <div id="Description">
            <asp:Repeater ID="Repeater5" runat="server" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <%# Eval("Description") %>
                </ItemTemplate>
            </asp:Repeater>
        </div>
        <h3>
            Review</h3>
        <br />
        <br />
        <div id="Review">
            <asp:Repeater ID="Repeater6" runat="server" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <%# Eval("Review") %>
                </ItemTemplate>
            </asp:Repeater>
        </div>
    </div>
    <div class="Ratings">
            <br />
            <br />
            <h3>Rating</h3>
            <br />
            <br />
            <asp:Label ID="Label1" CssClass="RatingNameLabel1" runat="server" Text="Average Rating" />
        <asp:UpdatePanel ID="RatingPanel" runat="server">
            <ContentTemplate>
                <asp:Repeater ID="Repeater7" runat="server" DataSourceID="SqlDataSource5">
                    <ItemTemplate>
                        <div class="ImageRating">
                            <img src="../../<%# getRating(Eval("AverageRating")) %>" alt="No picture found" width="120"
                                height="30" />
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <asp:Label ID="Label2" CssClass="RatingNameLabel1" runat="server" Text="Your Rating" />
                <asp:Repeater ID="Repeater8" runat="server" DataSourceID="SqlDataSource6" Visible="false">
                    <ItemTemplate>
                        <div class="ImageRating">
                            <img src="../../<%# getRating(Eval("UserRating")) %>" alt="No picture found" width="120"
                                height="30" />
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <asp:Button ID="btn_Change" runat="server" Text="Change your Rating!" CssClass="m-btn blue"
                    Visible="false" />
                <ajaxToolkit:Rating ID="Rating1" runat="server" EmptyStarCssClass="emptypng" FilledStarCssClass="smileypng"
                    StarCssClass="smileypng" WaitingStarCssClass="donesmileypng" HorizontalAlign="Left">
                </ajaxToolkit:Rating>
                <p>
                    <asp:Button ID="btn_Rating" runat="server" Text="Rate it!" CssClass="m-btn blue" />
                </p>
            </ContentTemplate>
        </asp:UpdatePanel>
        </div>
    <br />
    <br />
     <div style="clear:both"></div>
    <div class="CommentsDetailsArea">
        
                <h2>
                    <%= getTotalComments() %></h2>
                <table>
                    <tr>
                        <td>
                            Title
                        </td>
                        <td>
                            <asp:TextBox ID="tb_Title" runat="server"></asp:TextBox><asp:RequiredFieldValidator
                                ID="RequiredFieldValidator1" runat="server" ControlToValidate="tb_Title" CssClass="field-validation-error"
                                ErrorMessage="*" ValidationGroup="CommentGroup"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Comment
                        </td>
                        <td>
                            <asp:TextBox ID="tb_Comment" runat="server" TextMode="MultiLine" Height="75px" Width="300px"></asp:TextBox><asp:RequiredFieldValidator
                                ID="RequiredFieldValidator2" runat="server" ControlToValidate="tb_Comment" CssClass="field-validation-error"
                                ErrorMessage="*" ValidationGroup="CommentGroup"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </table>
                <asp:Button ID="btn_Comment" runat="server" CommandArgument="0" OnClick="Button_Click"
                    Text="Add Comment" ValidationGroup="CommentGroup" CssClass="m-btn blue" />
                <hr />
                <div id="ContentWraper">
                    <asp:Literal ID="CommentsLtr" runat="server"></asp:Literal></div>
                <br />
    </div>

    <div class="TagsArea">
        <div id="TagContentWraper">
            <h2>Tags</h2>
                    <div class="CloudBox">
                        <br />
                        <asp:Literal ID="CloudTags" runat="server"></asp:Literal></div>
                        <asp:CheckBoxList ID="cbl_Tags" runat="server" DataSourceID="SqlDataSource3" DataTextField="Tag"
                        DataValueField="ID" RepeatDirection="Horizontal" RepeatColumns="3" ForeColor="#7AC0DA" Font-Size="X-Small">
                    </asp:CheckBoxList>
                    <br />
                    Enter new tags, separated by (",")
                    <br />
                    <asp:TextBox ID="tb_Tags" runat="server"></asp:TextBox>
                    <br />
                    <asp:Button ID="btn_Tag" runat="server" Text="Tag" CssClass="m-btn blue" />
                    <asp:Label ID="lbl_Tag" runat="server" CssClass="error"></asp:Label><br />
        </div>
    </div>

    <div class="TagsArea">
        <h2 id="myHeading" runat="server"></h2>
        <br />
        <asp:Repeater ID="Repeater10" runat="server" DataSourceID="SqlDataSource7">

            <ItemTemplate>
                <a id="RepeaterStyle" href="ViewQuestion.aspx?Question=<%# Eval("ID") %>&Book_FK=<%# Eval("Book_FK") %>">
                    <%# "Chapter : " & Eval("Chapter") & " Question : " & Eval("Question_Number") %></a>
            </ItemTemplate>
        </asp:Repeater>
    </div>












    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>" SelectCommand="SELECT * FROM [Books_Categories_View] WHERE ([ID] = @ID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>" SelectCommand="SELECT * FROM [TotalLikesPerBook] WHERE ([ID] = @Book_FK)">
        <SelectParameters>
            <asp:QueryStringParameter Name="Book_FK" QueryStringField="ID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>" 
        SelectCommand="SELECT [ID], [Tag] FROM [Tags]">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>"
         SelectCommand="SELECT BookTagJunction.Tag_FK, Count(BookTagJunction.Tag_FK) AS TotalTags, Tags.Tag, BookTagJunction.Book_FK
                            FROM Tags INNER JOIN BookTagJunction ON (Tags.ID = BookTagJunction.Tag_FK) WHERE (BookTagJunction.Book_FK = @Book_FK)
                            GROUP BY BookTagJunction.Tag_FK, Tags.Tag, BookTagJunction.Book_FK">
        <SelectParameters>
            <asp:QueryStringParameter Name="Book_FK" QueryStringField="ID"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>"
                    ProviderName="<%$ ConnectionStrings:BooksReviewDBConnectionString1.ProviderName %>" SelectCommand="SELECT * FROM [BookAverageRating] WHERE ([Book_FK] = @Book_FK)">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="Book_FK" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>"
                    ProviderName="<%$ ConnectionStrings:BooksReviewDBConnectionString1.ProviderName %>" SelectCommand="SELECT * FROM [BookUserRating] WHERE ([Book_FK] = @Book_FK) AND ([Bibliophile] = @Bibliophile)">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="Book_FK" QueryStringField="ID" Type="Int32" />
                        <asp:Parameter Name="Bibliophile" Type="String" />
                    </SelectParameters>
    </asp:SqlDataSource>
    
     <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:BooksReviewDBConnectionString1 %>"
                            ProviderName="<%$ ConnectionStrings:BooksReviewDBConnectionString1.ProviderName %>" SelectCommand="SELECT DISTINCT * FROM [Questions] WHERE ([Book_FK] =  @Book_FK) ORDER BY Chapter DESC, Question_Number DESC">
                            <SelectParameters>
                                <asp:QueryStringParameter Name="Book_FK" QueryStringField="ID" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
</asp:Content>
